package com.shrct.businessprocess.purchase.impl;

import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import com.shrct.businessprocess.budget.RCBudgetDivision;
import com.shrct.businessprocess.budget.RCBudgetStatus;
import com.shrct.businessprocess.budget.RCCost4RemainItem;
import com.shrct.businessprocess.budget.RCCostBreakDown;
import com.shrct.businessprocess.diagnose.IDiagnoseAcceptor;
import com.shrct.businessprocess.product.RCBrand;
import com.shrct.businessprocess.product.RCProductMetaType;
import com.shrct.businessprocess.product.RCProductServiceTracer;
import com.shrct.businessprocess.product.impl.RCBrandImpl;
import com.shrct.businessprocess.project.RCProject;
import com.shrct.businessprocess.project.RCProjectMoney;
import com.shrct.businessprocess.purchase.RCBasePurchaseRequest;
import com.shrct.businessprocess.purchase.RCHasPurchaseBudget;
import com.shrct.businessprocess.purchase.RCProductPurchaseBudget;
import com.shrct.businessprocess.purchase.RCProductPurchaseItem;
import com.shrct.businessprocess.purchase.RCServiceProductPurchaseRequest;
import com.shrct.businessprocess.purchase.impl.RCBaseProductPurchaseBudgetImpl;
import com.shrct.businessprocess.purchase.impl.RCServiceProductPurchaseRequestImpl;
import com.shrct.businessprocess.purchase.proxy.RCProductPurchaseBudgetProxy;
import edu.fudan.mylang.pf.IGenericQuery;
import edu.fudan.mylang.pf.IObjectFactory;
import edu.fudan.mylang.utils.DateUtil;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.DoubleExtensions;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

@Entity
@DiscriminatorValue("RCPRODUCTPURCHASEBUDGET_TYPE")
public class RCProductPurchaseBudgetImpl extends RCBaseProductPurchaseBudgetImpl implements RCProductPurchaseBudget {
  public RCProductPurchaseBudgetImpl() {
    super();
  }
  
  public RCProductPurchaseBudgetImpl(final RCCostBreakDown cbd) {
    super( cbd);
    
  }
  
  @Embedded
  @AttributeOverrides(value = { @AttributeOverride(name = "amount", column = @Column(name = "serviceContractPrice_amount") ), @AttributeOverride(name = "workaround", column = @Column(name = "serviceContractPrice_workaround") ) } )
  @AssociationOverrides(value = @AssociationOverride(name = "exchange", joinColumns = @JoinColumn(name = "serviceContractPrice_exchange") ) )
  private RCProjectMoney serviceContractPrice = com.shrct.businessprocess.project.RCProjectMoney.create();
  
  public RCProjectMoney getServiceContractPrice() {
    return this.serviceContractPrice;
  }
  
  public RCProductPurchaseBudget setServiceContractPrice(final RCProjectMoney serviceContractPrice) {
    this.serviceContractPrice = serviceContractPrice;
    return this;			
    
  }
  
  private Double serviceContractTaxRate;
  
  public Double getServiceContractTaxRate() {
    return this.serviceContractTaxRate;
  }
  
  public RCProductPurchaseBudget setServiceContractTaxRate(final Double serviceContractTaxRate) {
    this.serviceContractTaxRate = serviceContractTaxRate;
    return this;			
    
  }
  
  @Embedded
  @AttributeOverrides(value = { @AttributeOverride(name = "amount", column = @Column(name = "serviceNetPrice_amount") ), @AttributeOverride(name = "workaround", column = @Column(name = "serviceNetPrice_workaround") ) } )
  @AssociationOverrides(value = @AssociationOverride(name = "exchange", joinColumns = @JoinColumn(name = "serviceNetPrice_exchange") ) )
  private RCProjectMoney serviceNetPrice = com.shrct.businessprocess.project.RCProjectMoney.create();
  
  public RCProjectMoney getServiceNetPrice() {
    return this.serviceNetPrice;
  }
  
  public RCProductPurchaseBudget setServiceNetPrice(final RCProjectMoney serviceNetPrice) {
    this.serviceNetPrice = serviceNetPrice;
    return this;			
    
  }
  
  private Double serviceNetTaxRate;
  
  public Double getServiceNetTaxRate() {
    return this.serviceNetTaxRate;
  }
  
  public RCProductPurchaseBudget setServiceNetTaxRate(final Double serviceNetTaxRate) {
    this.serviceNetTaxRate = serviceNetTaxRate;
    return this;			
    
  }
  
  @Embedded
  @AttributeOverrides(value = { @AttributeOverride(name = "amount", column = @Column(name = "productContractPrice_amount") ), @AttributeOverride(name = "workaround", column = @Column(name = "productContractPrice_workaround") ) } )
  @AssociationOverrides(value = @AssociationOverride(name = "exchange", joinColumns = @JoinColumn(name = "productContractPrice_exchange") ) )
  private RCProjectMoney productContractPrice = com.shrct.businessprocess.project.RCProjectMoney.create();
  
  public RCProjectMoney getProductContractPrice() {
    return this.productContractPrice;
  }
  
  public RCProductPurchaseBudget setProductContractPrice(final RCProjectMoney productContractPrice) {
    this.productContractPrice = productContractPrice;
    return this;			
    
  }
  
  private Double productContractTaxRate;
  
  public Double getProductContractTaxRate() {
    return this.productContractTaxRate;
  }
  
  public RCProductPurchaseBudget setProductContractTaxRate(final Double productContractTaxRate) {
    this.productContractTaxRate = productContractTaxRate;
    return this;			
    
  }
  
  @Embedded
  @AttributeOverrides(value = { @AttributeOverride(name = "amount", column = @Column(name = "productNetPrice_amount") ), @AttributeOverride(name = "workaround", column = @Column(name = "productNetPrice_workaround") ) } )
  @AssociationOverrides(value = @AssociationOverride(name = "exchange", joinColumns = @JoinColumn(name = "productNetPrice_exchange") ) )
  private RCProjectMoney productNetPrice = com.shrct.businessprocess.project.RCProjectMoney.create();
  
  public RCProjectMoney getProductNetPrice() {
    return this.productNetPrice;
  }
  
  public RCProductPurchaseBudget setProductNetPrice(final RCProjectMoney productNetPrice) {
    this.productNetPrice = productNetPrice;
    return this;			
    
  }
  
  private Double productNetTaxRate;
  
  public Double getProductNetTaxRate() {
    return this.productNetTaxRate;
  }
  
  public RCProductPurchaseBudget setProductNetTaxRate(final Double productNetTaxRate) {
    this.productNetTaxRate = productNetTaxRate;
    return this;			
    
  }
  
  @JoinColumn(name = "productCategory_id")
  @ManyToOne(targetEntity = RCBrandImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCBrand productCategory;
  
  public RCBrand getProductCategory() {
    return this.productCategory;
  }
  
  public RCProductPurchaseBudget setProductCategory(final RCBrand productCategory) {
    this.productCategory = productCategory;
    return this;			
    
  }
  
  public String getSortKey() {
    String _typeId = this.getTypeId();
    String _codeid = this.productCategory.getCodeid();
    String _plus = (_typeId + _codeid);
    return _plus;
  }
  
  public String getName() {
    String _name = this.productCategory==null?(String)null:this.productCategory.getName();
    return _name;
  }
  
  public RCProjectMoney getContractPrice() {
    RCProjectMoney _plus = this.productContractPrice.plus(this.serviceContractPrice);
    return _plus;
  }
  
  public Double getContractTaxRate() {
    return Double.valueOf(0d);
  }
  
  public RCProjectMoney getNetPrice() {
    RCProjectMoney _plus = this.productNetPrice.plus(this.serviceNetPrice);
    return _plus;
  }
  
  public Double getNetTaxRate() {
    return Double.valueOf(0d);
  }
  
  public String getTypeId() {
    return "RCAXBudget";
  }
  
  public RCProductMetaType getProductMetaType() {
    return RCProductMetaType.identifiable;
  }
  
  public Boolean seemsFinished() {
    boolean _xifexpression = false;
    RCBudgetStatus _budgetStatus = this.getBudgetStatus();
    boolean _equals = Objects.equal(_budgetStatus, RCBudgetStatus.unset);
    if (_equals) {
      boolean _xblockexpression = false;
      {
        final Collection<RCProductPurchaseItem> items = this.getItems();
        boolean _xifexpression_1 = false;
        boolean _and = false;
        int _size = items.size();
        boolean _equals_1 = (_size == 0);
        if (!_equals_1) {
          _and = false;
        } else {
          boolean _or = false;
          RCProjectMoney _contractPrice = this.getContractPrice();
          Double _amount = _contractPrice.getAmount();
          boolean _notEquals = ((_amount).doubleValue() != 0d);
          if (_notEquals) {
            _or = true;
          } else {
            RCProjectMoney _netPrice = this.getNetPrice();
            Double _amount_1 = _netPrice.getAmount();
            boolean _notEquals_1 = ((_amount_1).doubleValue() != 0);
            _or = (_notEquals || _notEquals_1);
          }
          _and = (_equals_1 && _or);
        }
        if (_and) {
          _xifexpression_1 = false;
        } else {
          boolean _and_1 = false;
          final Function1<RCProductPurchaseItem,Boolean> _function = new Function1<RCProductPurchaseItem,Boolean>() {
              public Boolean apply(final RCProductPurchaseItem it) {
                boolean _and = false;
                Integer _orderQuantity = it.getOrderQuantity();
                Integer _quantity = it.getQuantity();
                boolean _greaterEqualsThan = (_orderQuantity.compareTo(_quantity) >= 0);
                if (!_greaterEqualsThan) {
                  _and = false;
                } else {
                  Integer _deliveredQuantity = it.getDeliveredQuantity();
                  Integer _orderQuantity_1 = it.getOrderQuantity();
                  boolean _greaterEqualsThan_1 = (_deliveredQuantity.compareTo(_orderQuantity_1) >= 0);
                  _and = (_greaterEqualsThan && _greaterEqualsThan_1);
                }
                return Boolean.valueOf(_and);
              }
            };
          boolean _forall = IterableExtensions.<RCProductPurchaseItem>forall(items, _function);
          if (!_forall) {
            _and_1 = false;
          } else {
            boolean _or_1 = false;
            Iterable<RCProductServiceTracer> _rCProductServiceTracer = this.getRCProductServiceTracer();
            int _size_1 = IterableExtensions.size(_rCProductServiceTracer);
            boolean _equals_2 = (_size_1 == 0);
            if (_equals_2) {
              _or_1 = true;
            } else {
              Iterable<RCProductServiceTracer> _rCProductServiceTracer_1 = this.getRCProductServiceTracer();
              final Function1<RCProductServiceTracer,Boolean> _function_1 = new Function1<RCProductServiceTracer,Boolean>() {
                  public Boolean apply(final RCProductServiceTracer it) {
                    Boolean _needAdditionalPurchase = it.needAdditionalPurchase();
                    boolean _not = (!_needAdditionalPurchase);
                    return Boolean.valueOf(_not);
                  }
                };
              boolean _forall_1 = IterableExtensions.<RCProductServiceTracer>forall(_rCProductServiceTracer_1, _function_1);
              _or_1 = (_equals_2 || _forall_1);
            }
            _and_1 = (_forall && _or_1);
          }
          _xifexpression_1 = _and_1;
        }
        _xblockexpression = (_xifexpression_1);
      }
      _xifexpression = _xblockexpression;
    } else {
      RCBudgetStatus _budgetStatus_1 = this.getBudgetStatus();
      boolean _equals_1 = Objects.equal(_budgetStatus_1, RCBudgetStatus.finished);
      _xifexpression = _equals_1;
    }
    return Boolean.valueOf(_xifexpression);
  }
  
  public Collection<RCBudgetDivision> getBudgetDivisions() {
    ArrayList<RCBudgetDivision> _newArrayList = CollectionLiterals.<RCBudgetDivision>newArrayList();
    final Procedure1<ArrayList<RCBudgetDivision>> _function = new Procedure1<ArrayList<RCBudgetDivision>>() {
        public void apply(final ArrayList<RCBudgetDivision> it) {
          RCBudgetDivision _rCBudgetDivision = new RCBudgetDivision();
          final Procedure1<RCBudgetDivision> _function = new Procedure1<RCBudgetDivision>() {
              public void apply(final RCBudgetDivision it) {
                it.setName("\u4EA7\u54C1");
                it.setContractPrice(RCProductPurchaseBudgetImpl.this.productContractPrice);
                it.setContractTaxRate(RCProductPurchaseBudgetImpl.this.productContractTaxRate);
                it.setNetPrice(RCProductPurchaseBudgetImpl.this.productNetPrice);
                it.setNetTaxRate(RCProductPurchaseBudgetImpl.this.productNetTaxRate);
                RCProjectMoney _totalOrderAmount4Product = RCProductPurchaseBudgetImpl.this.getTotalOrderAmount4Product();
                it.setActualCost(_totalOrderAmount4Product);
              }
            };
          RCBudgetDivision _doubleArrow = ObjectExtensions.<RCBudgetDivision>operator_doubleArrow(_rCBudgetDivision, _function);
          it.add(_doubleArrow);
          RCBudgetDivision _rCBudgetDivision_1 = new RCBudgetDivision();
          final Procedure1<RCBudgetDivision> _function_1 = new Procedure1<RCBudgetDivision>() {
              public void apply(final RCBudgetDivision it) {
                it.setName("\u670D\u52A1");
                it.setContractPrice(RCProductPurchaseBudgetImpl.this.serviceContractPrice);
                it.setContractTaxRate(RCProductPurchaseBudgetImpl.this.serviceContractTaxRate);
                it.setNetPrice(RCProductPurchaseBudgetImpl.this.serviceNetPrice);
                it.setNetTaxRate(RCProductPurchaseBudgetImpl.this.serviceNetTaxRate);
                RCProjectMoney _totalOrderAmount4Service = RCProductPurchaseBudgetImpl.this.getTotalOrderAmount4Service();
                it.setActualCost(_totalOrderAmount4Service);
              }
            };
          RCBudgetDivision _doubleArrow_1 = ObjectExtensions.<RCBudgetDivision>operator_doubleArrow(_rCBudgetDivision_1, _function_1);
          it.add(_doubleArrow_1);
          RCBudgetDivision _rCBudgetDivision_2 = new RCBudgetDivision();
          final Procedure1<RCBudgetDivision> _function_2 = new Procedure1<RCBudgetDivision>() {
              public void apply(final RCBudgetDivision it) {
                it.setName("\u5176\u4ED6");
                RCCostBreakDown _cbd = RCProductPurchaseBudgetImpl.this.getCbd();
                RCProject _project = _cbd.getProject();
                RCProjectMoney _zeroAmount = _project.getZeroAmount();
                it.setContractPrice(_zeroAmount);
                it.setContractTaxRate(Double.valueOf(0d));
                RCCostBreakDown _cbd_1 = RCProductPurchaseBudgetImpl.this.getCbd();
                RCProject _project_1 = _cbd_1.getProject();
                RCProjectMoney _zeroAmount_1 = _project_1.getZeroAmount();
                it.setNetPrice(_zeroAmount_1);
                it.setNetTaxRate(Double.valueOf(0d));
                RCProjectMoney _totalOtherAmount = RCProductPurchaseBudgetImpl.this.getTotalOtherAmount();
                it.setActualCost(_totalOtherAmount);
              }
            };
          RCBudgetDivision _doubleArrow_2 = ObjectExtensions.<RCBudgetDivision>operator_doubleArrow(_rCBudgetDivision_2, _function_2);
          it.add(_doubleArrow_2);
        }
      };
    ArrayList<RCBudgetDivision> _doubleArrow = ObjectExtensions.<ArrayList<RCBudgetDivision>>operator_doubleArrow(_newArrayList, _function);
    return _doubleArrow;
  }
  
  public Iterable<RCCost4RemainItem> getRCCost4RemainItems() {
    Iterable<RCCost4RemainItem> _xblockexpression = null;
    {
      Boolean _seemsFinished = this.seemsFinished();
      if ((_seemsFinished).booleanValue()) {
        return CollectionLiterals.<RCCost4RemainItem>newArrayList();
      }
      RCCost4RemainItem _rCCost4RemainItem = new RCCost4RemainItem();
      final Procedure1<RCCost4RemainItem> _function = new Procedure1<RCCost4RemainItem>() {
          public void apply(final RCCost4RemainItem it) {
            it.setBudget(RCProductPurchaseBudgetImpl.this);
            String _entityName = RCProductPurchaseBudgetImpl.this.getEntityName();
            String _plus = (_entityName + ":\u4EA7\u54C1");
            it.setTitle(_plus);
            Double _hostAmount = RCProductPurchaseBudgetImpl.this.productNetPrice.toHostAmount();
            Double _totalACTOrderAmount4Product = RCProductPurchaseBudgetImpl.this.getTotalACTOrderAmount4Product();
            double _minus = DoubleExtensions.operator_minus(_hostAmount, _totalACTOrderAmount4Product);
            it.setAmount(Double.valueOf(_minus));
            it.setTaxRate(RCProductPurchaseBudgetImpl.this.productNetTaxRate);
          }
        };
      RCCost4RemainItem _doubleArrow = ObjectExtensions.<RCCost4RemainItem>operator_doubleArrow(_rCCost4RemainItem, _function);
      RCCost4RemainItem _rCCost4RemainItem_1 = new RCCost4RemainItem();
      final Procedure1<RCCost4RemainItem> _function_1 = new Procedure1<RCCost4RemainItem>() {
          public void apply(final RCCost4RemainItem it) {
            it.setBudget(RCProductPurchaseBudgetImpl.this);
            String _entityName = RCProductPurchaseBudgetImpl.this.getEntityName();
            String _plus = (_entityName + ":\u670D\u52A1");
            it.setTitle(_plus);
            Double _hostAmount = RCProductPurchaseBudgetImpl.this.serviceNetPrice.toHostAmount();
            Double _totalACTOrderAmount4Service = RCProductPurchaseBudgetImpl.this.getTotalACTOrderAmount4Service();
            double _minus = DoubleExtensions.operator_minus(_hostAmount, _totalACTOrderAmount4Service);
            it.setAmount(Double.valueOf(_minus));
            it.setTaxRate(RCProductPurchaseBudgetImpl.this.serviceNetTaxRate);
          }
        };
      RCCost4RemainItem _doubleArrow_1 = ObjectExtensions.<RCCost4RemainItem>operator_doubleArrow(_rCCost4RemainItem_1, _function_1);
      ArrayList<RCCost4RemainItem> _newArrayList = CollectionLiterals.<RCCost4RemainItem>newArrayList(_doubleArrow, _doubleArrow_1);
      final Function1<RCCost4RemainItem,Boolean> _function_2 = new Function1<RCCost4RemainItem,Boolean>() {
          public Boolean apply(final RCCost4RemainItem it) {
            Double _amount = it.getAmount();
            boolean _greaterThan = ((_amount).doubleValue() > 0);
            return Boolean.valueOf(_greaterThan);
          }
        };
      Iterable<RCCost4RemainItem> _filter = IterableExtensions.<RCCost4RemainItem>filter(_newArrayList, _function_2);
      _xblockexpression = (_filter);
    }
    return _xblockexpression;
  }
  
  public RCProjectMoney getContractInvoiceTax() {
    RCProjectMoney _xblockexpression = null;
    {
      RCProjectMoney _productContractPrice = this.getProductContractPrice();
      double _divide = ((this.productContractTaxRate).doubleValue() / 100);
      double _plus = (1 + _divide);
      RCProjectMoney _div = _productContractPrice.div(Double.valueOf(_plus));
      double _divide_1 = ((this.productContractTaxRate).doubleValue() / 100);
      final RCProjectMoney productTax = _div.multi(Double.valueOf(_divide_1));
      RCProjectMoney _serviceContractPrice = this.getServiceContractPrice();
      double _divide_2 = ((this.serviceContractTaxRate).doubleValue() / 100);
      double _plus_1 = (1 + _divide_2);
      RCProjectMoney _div_1 = _serviceContractPrice.div(Double.valueOf(_plus_1));
      double _divide_3 = ((this.serviceContractTaxRate).doubleValue() / 100);
      final RCProjectMoney serviceTax = _div_1.multi(Double.valueOf(_divide_3));
      RCProjectMoney _plus_2 = productTax.plus(serviceTax);
      _xblockexpression = (_plus_2);
    }
    return _xblockexpression;
  }
  
  public RCProjectMoney getNetInvoiceTax() {
    RCProjectMoney _xblockexpression = null;
    {
      RCProjectMoney _productNetPrice = this.getProductNetPrice();
      double _divide = ((this.productNetTaxRate).doubleValue() / 100);
      double _plus = (1 + _divide);
      RCProjectMoney _div = _productNetPrice.div(Double.valueOf(_plus));
      double _divide_1 = ((this.productNetTaxRate).doubleValue() / 100);
      final RCProjectMoney productTax = _div.multi(Double.valueOf(_divide_1));
      RCProjectMoney _serviceNetPrice = this.getServiceNetPrice();
      double _divide_2 = ((this.serviceNetTaxRate).doubleValue() / 100);
      double _plus_1 = (1 + _divide_2);
      RCProjectMoney _div_1 = _serviceNetPrice.div(Double.valueOf(_plus_1));
      double _divide_3 = ((this.serviceNetTaxRate).doubleValue() / 100);
      final RCProjectMoney serviceTax = _div_1.multi(Double.valueOf(_divide_3));
      RCProjectMoney _plus_2 = productTax.plus(serviceTax);
      _xblockexpression = (_plus_2);
    }
    return _xblockexpression;
  }
  
  public RCProjectMoney getInvoiceTax() {
    RCProjectMoney _xblockexpression = null;
    {
      RCProjectMoney _productContractPrice = this.getProductContractPrice();
      double _divide = ((this.productContractTaxRate).doubleValue() / 100);
      double _plus = (1 + _divide);
      RCProjectMoney _div = _productContractPrice.div(Double.valueOf(_plus));
      double _divide_1 = ((this.productContractTaxRate).doubleValue() / 100);
      RCProjectMoney _multi = _div.multi(Double.valueOf(_divide_1));
      RCProjectMoney _productNetPrice = this.getProductNetPrice();
      double _divide_2 = ((this.productNetTaxRate).doubleValue() / 100);
      double _plus_1 = (1 + _divide_2);
      RCProjectMoney _div_1 = _productNetPrice.div(Double.valueOf(_plus_1));
      double _divide_3 = ((this.productNetTaxRate).doubleValue() / 100);
      RCProjectMoney _multi_1 = _div_1.multi(Double.valueOf(_divide_3));
      final RCProjectMoney productTax = _multi.substract(_multi_1);
      RCProjectMoney _serviceContractPrice = this.getServiceContractPrice();
      double _divide_4 = ((this.serviceContractTaxRate).doubleValue() / 100);
      double _plus_2 = (1 + _divide_4);
      RCProjectMoney _div_2 = _serviceContractPrice.div(Double.valueOf(_plus_2));
      double _divide_5 = ((this.serviceContractTaxRate).doubleValue() / 100);
      RCProjectMoney _multi_2 = _div_2.multi(Double.valueOf(_divide_5));
      RCProjectMoney _serviceNetPrice = this.getServiceNetPrice();
      double _divide_6 = ((this.serviceNetTaxRate).doubleValue() / 100);
      double _plus_3 = (1 + _divide_6);
      RCProjectMoney _div_3 = _serviceNetPrice.div(Double.valueOf(_plus_3));
      double _divide_7 = ((this.serviceNetTaxRate).doubleValue() / 100);
      RCProjectMoney _multi_3 = _div_3.multi(Double.valueOf(_divide_7));
      final RCProjectMoney serviceTax = _multi_2.substract(_multi_3);
      RCProjectMoney _plus_4 = productTax.plus(serviceTax);
      _xblockexpression = (_plus_4);
    }
    return _xblockexpression;
  }
  
  public RCServiceProductPurchaseRequest createServiceProductPurchaseRequest() {RCServiceProductPurchaseRequest rCServiceProductPurchaseRequest=RCServiceProductPurchaseRequestImpl.create(this,getObjectFactory());
    final Procedure1<RCServiceProductPurchaseRequest> _function = new Procedure1<RCServiceProductPurchaseRequest>() {
        public void apply(final RCServiceProductPurchaseRequest it) {
          Date _day = DateUtil.today();
          it.setDate(_day);
        }
      };
    RCServiceProductPurchaseRequest _doubleArrow = ObjectExtensions.<RCServiceProductPurchaseRequest>operator_doubleArrow(rCServiceProductPurchaseRequest, _function);
    return _doubleArrow;
  }
  
  public Iterable<RCServiceProductPurchaseRequest> getServicePurchaseRequests() {
    Collection<RCBasePurchaseRequest> _purchaseRequests = this.getPurchaseRequests();
    Iterable<RCServiceProductPurchaseRequest> _filter = Iterables.<RCServiceProductPurchaseRequest>filter(_purchaseRequests, RCServiceProductPurchaseRequest.class);
    return _filter;
  }
  
  public Iterable<RCProductServiceTracer> getRCProductServiceTracer() {
    IGenericQuery<RCProductServiceTracer> query=getObjectFactory().createGenericQuery(RCProductServiceTracer.class,"select e from com.shrct.businessprocess.product.impl.RCProductServiceTracerImpl as e   where ((e.budgetContract.budget) = (:this)) and  e.active = 1      ").setParameter("this",this);
    Collection<RCProductServiceTracer> _list = query.list();
    return _list;
  }
  
  public RCHasPurchaseBudget asBudget() {
    return this;
  }
  
  public void diagnose(final IDiagnoseAcceptor acceptor) {
  }
  
  public static RCProductPurchaseBudget create(final RCCostBreakDown cbd, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.purchase.RCProductPurchaseBudget rCProductPurchaseBudget = new com.shrct.businessprocess.purchase.impl.RCProductPurchaseBudgetImpl(
    	cbd
    );
    objectFactory.create(rCProductPurchaseBudget);
    return rCProductPurchaseBudget;			
    
  }
  
  public static RCProductPurchaseBudget createRCProductPurchaseBudgetImpl(final RCCostBreakDown cbd, final IObjectFactory objectFactory, final Procedure1<RCProductPurchaseBudget> init) {
    com.shrct.businessprocess.purchase.RCProductPurchaseBudget rCProductPurchaseBudget = new com.shrct.businessprocess.purchase.impl.RCProductPurchaseBudgetImpl(
    	cbd
    );
    objectFactory.create(rCProductPurchaseBudget);
    init.apply(rCProductPurchaseBudget);
    
    return rCProductPurchaseBudget;			
    
  }
  
  public RCProductPurchaseBudgetProxy toProxy() {
    com.shrct.businessprocess.purchase.proxy.RCProductPurchaseBudgetProxy proxy = new com.shrct.businessprocess.purchase.proxy.RCProductPurchaseBudgetProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
